Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

314
Vistas
How to get the substring from between two [ ] braces in a string in javascript or jquery

My string looks like this street no [12]

I need to extract the 12 alone from the string.

How do I get the substring between two [ ] in javascript or jquery?

find the substring between first matching [] brackets

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

I noted that your requirements changed in a comment below the previous answer, to fix that issue you can change the regex adding ? so it will capture the least possible matches.

const myString = "street no [12][22]"
const match = myString.match(/\[(.+?)\]/);
const myNumber = match && match[1];
console.log(myNumber);

Or, you can just capture digits if that works better for your needs

const myString = "street no [12][22]"
const match = myString.match(/\[(\d+)\]/);
const myNumber = match && match[1];
console.log(myNumber);

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can use a regular expression for this:

const myString = "street no [12]"
const match = myString.match(/\[(.+)\]/);
const myNumber = match && match[1];
console.log(myNumber);

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda